import { Controller, Post, Get, Body, Param, Query, UseGuards } from '@nestjs/common';
import { SequenceService } from '@/services/sequence.service';
import { JwtAuthGuard } from '@/guards/jwt-auth.guard';
import { GenerateSequenceDto, BatchGenerateSequenceDto, ResetSequenceDto } from '@/dto/sequence.dto';

@Controller('sequence')
@UseGuards(JwtAuthGuard)
export class SequenceController {
    constructor(private readonly sequenceService: SequenceService) {}

    /**
     * 生成下一个序列号
     */
    @Post('generate')
    async generateNext(@Body() config: GenerateSequenceDto) {
        return await this.sequenceService.generateNext(config);
    }

    /**
     * 批量生成序列号
     */
    @Post('generate/batch')
    async generateBatch(@Body() config: BatchGenerateSequenceDto) {
        return await this.sequenceService.generateBatch(config, config.count);
    }

    /**
     * 获取序列号信息
     */
    @Get('info/:type')
    async getSequenceInfo(@Param('type') type: string, @Query('date') date?: string) {
        return await this.sequenceService.getSequenceInfo(type, date);
    }

    /**
     * 重置序列号
     */
    @Post('reset/:type')
    async resetSequence(@Param('type') type: string, @Query('date') date?: string) {
        await this.sequenceService.resetSequence(type, date);
        return { message: '序列号重置成功' };
    }

    /**
     * 获取统计信息
     */
    @Get('statistics')
    async getStatistics() {
        return await this.sequenceService.getStatistics();
    }
}
